import { fileupload, downloadFile } from "../api/contract";
// 点击按钮后获取文件的信息，转换为formDate对象
//上传文件
export function upload(dataFile) {
    // 原生 const dataFile = event.target.files[0];
    // 组件 const dataFile = event.raw;
    console.log("文件" + dataFile)
    if (!dataFile) {
        alert("请选择一个文件");
        return;
    }
    const formData = new FormData();
    formData.append('uploadfile', dataFile);
    console.log(formData.get('uploadfile'))
    return fileupload(formData).then(res => {
        if (res.code == 200) {
            console.log("成功：", res)
            alert('文件上传成功')
        } else {
            console.log("失败：", res)
            alert('文件上传失败')
        }

    })
}
//下载
export function download(fileName) {
    // const filename = fileName;
    downloadFile(fileName).then(res => {
        console.log(res)
        const url = window.URL.createObjectURL(new Blob([res.data]))
        const link = document.createElement('a');
        link.href = url;
        link.setAttribute('download', fileName);
        document.body.appendChild(link);
        link.click();
    })
}
//获取头像
// getAvatar(){
//     getAvatar().then(res => {
//         console.log(res.message)
//         this.imageSrc = res.message
//     })
// }
